<template>
  <div class="comment-reply">
    <!-- 导航栏 -->
    <van-nav-bar :title="comment.reply_count > 0 ? comment.reply_count + '条回复' : '暂无回复'">
      <van-icon slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>
    <!-- /导航栏 -->
    <!-- 当前评论项 -->
    <comment-item :comment="comment"></comment-item>
    <!-- /当前评论项 -->
    <van-cell title="所有回复" />
    <!-- 评论的回复列表 -->
    <article-comment :source="comment.com_id" type="c" :list="list"></article-comment>
    <!-- /评论的回复列表 -->
    <!-- 底部 -->
    <div class="post-area">
      <van-button size="mini" round @click="postRepalyShow = true">写评论</van-button>
    </div>
    <!-- /底部 -->
    <van-popup v-model="postRepalyShow" position="bottom">
      <comment-post :target="comment.com_id" @comment-success="onSuccess"></comment-post>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item'
import ArticleComment from './article-comment'
import CommentPost from './comment-post.vue'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    ArticleComment,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      message: '',
      postRepalyShow: false,
      list: []
    }
  },
  methods: {
    onSuccess (data) {
      this.postRepalyShow = false
      this.comment.reply_count++
      this.list.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
/deep/ .van-list {
  margin-bottom: 88px;
}
.post-comment {
  display: flex;
  padding: 15px;
  align-items: flex-end;
  .post-field {
    background: #f5f7f9;
    margin-right: 15px;
  }
}
.post-area {
  height: 88px;
  width: 100vw;
  position: fixed;
  bottom: 0;
  background-color: pink;
  display: flex;
  justify-content: center;
  align-items: center;
  .van-button {
    width: 60%;
  }
}
</style>
